<?php

/* @var $this yii\web\View */

use yii\helpers\Html;

$this->title = '摩斯码';


$css = 'td,th{white-space:nowrap;padding:1px !important;}th{text-align:center}';
$this->registerCss($css);

?>
<script type="text/javascript">
    /**
     * Copyright (c) 2017 hustcc
     * License: MIT
     * Version: v0.0.3
     * GitHub: https://github.com/hustcc/xmorse
     **/
    !function(e,n){"object"==typeof module&&module.exports?module.exports=n():e.xmorse=n()}("undefined"!=typeof window?window:this,function(){function e(e){return e=e||{},[e.space||"/",e.short||".",e.long||"-"]}function n(e){for(var n=[],r=0;r<e.length;r++)n[r]=("00"+e.charCodeAt(r).toString(16)).slice(-4);return n=n.join(""),n=parseInt(n,16).toString(2)}function r(r,o){o=e(o);var t=[];r=r.replace(/\s+/g,"").toLocaleUpperCase().split("");for(var p,a,c=0,u=r.length;c<u;c++)p=r[c],a=i[p],a||(a=n(p)),t.push(a.replace(/0/g,o[1]).replace(/1/g,o[2]));return t.join(o[0])}function o(e){return e=parseInt(e,2),isNaN(e)?"":unescape("%u"+e.toString(16))}function t(n,r){r=e(r);var t=[];n=n.split(r[0]);for(var i,a,c=0,u=n.length;c<u;c++)i=n[c].replace(/\s+/g,"").replace(new RegExp("\\"+r[1],"g"),"0").replace(new RegExp("\\"+r[2],"g"),"1"),a=p[i],a||(a=o(i)),t.push(a);return t.join("")}var i={A:"01",B:"1000",C:"1010",D:"100",E:"0",F:"0010",G:"110",H:"0000",I:"00",J:"0111",K:"101",L:"0100",M:"11",N:"10",O:"111",P:"0110",Q:"1101",R:"010",S:"000",T:"1",U:"001",V:"0001",W:"011",X:"1001",Y:"1011",Z:"1100",0:"11111",1:"01111",2:"00111",3:"00011",4:"00001",5:"00000",6:"10000",7:"11000",8:"11100",9:"11110",".":"010101",",":"110011","?":"001100","'":"011110","!":"101011","/":"10010","(":"10110",")":"101101","&":"01000",":":"111000",";":"101010","=":"10001","+":"01010","-":"100001",_:"001101",'"':"010010",$:"0001001","@":"011010"},p={};for(var a in i)p[i[a]]=a;return{encode:r,decode:t}});

    function encode_morse_zh() {
        $('#result').text(xmorse.encode($('#ori').val()));
    }

    function decode_morse_zh() {
        $('#result').text(xmorse.decode($('#ori').val()) || "输入的摩斯码不符合要求！");
    }
</script>
<div class="site-index">
    <div class="body-content">
        <form method='post'>
            <h2 class="h24"><?php echo $this->title; ?></h2>
            <hr/>
            <div class="form-group">
                <label>原文：</label>
                <textarea  rows='2' name='ori' id='ori' class="form-control"></textarea>
            </div>
            <div class="form-group">
                <input type='button' class="btn btn-primary" value='转为摩斯码' onclick="encode_morse_zh()"/>
                <input type='button' class="btn btn-danger " value='解读摩斯码' onclick="decode_morse_zh()"/>
            </div>
        </form>
        <div class="form-group">
            <label>结果：</label>
            <textarea  rows='2' class="form-control" id="result"></textarea>
        </div>
    </div>
</div>


<h5>一、26个字母的莫尔斯电码加密</h5>　	　	　	　	　
<table class="table table-striped table-bordered">
    <tbody>
    <tr>
        <th width="8%"><strong>字符</strong></th>
        <td width="17%"><strong>电码符号</strong></td>
        <th width="8%"><strong>字符</strong></th>
        <td width="17%"><strong>电码符号</strong></td>
        <th width="8%"><strong>字符</strong></th>
        <td width="17%"><strong>电码符号</strong></td>
    </tr>
    <tr>
        <th>A</th>
        <td>．━</td>
        <th>B</th>
        <td>━ ．．．</td>
        <th>C</th>
        <td>━ ．━ ．</td>

    </tr>
    <tr>
        <th>D</th>
        <td>━ ．．</td>
        <th>E</th>
        <td>．</td>
        <th>F</th>
        <td>．．━ ．</td>

    </tr>
    <tr>
        <th>G</th>
        <td>━ ━ ．</td>
        <th>H</th>
        <td>．．．．</td>
        <th>I</th>
        <td>．．</td>
    </tr>
    <tr>
        <th>J</th>
        <td>．━ ━ ━</td>
        <th>K</th>
        <td>━ ．━</td>
        <th>L</th>
        <td>．━ ．．</td>

    </tr>
    <tr>
        <th>M</th>
        <td>━ ━</td>
        <th>N</th>
        <td>━ ．</td>
        <th>O</th>
        <td>━ ━ ━</td>

    </tr>
    <tr>
        <th>P</th>
        <td>．━ ━ ．</td>
        <th>Q</th>
        <td>━ ━ ．━</td>
        <th>R</th>
        <td>．━ ．</td>

    </tr>
    <tr>
        <th>S</th>
        <td>．．．</td>
        <th>T</th>
        <td>━</td>
        <th>U</th>
        <td>．．━</td>
    </tr>
    <tr>
        <th>V</th>
        <td>．．．━</td>
        <th>W</th>
        <td>．━ ━</td>
        <th>X</th>
        <td>━ ．．━</td>
    </tr>
    <tr>
        <th>Y</th>
        <td>━ ．━ ━</td>
        <th>Z</th>
        <td>━ ━ ．．</td>
        <th>　</th>
        <td>　</td>
    </tr>
    </tbody>
</table>
<h5>二、数字的莫尔斯电码加密</h5>
<table class="table table-striped table-bordered">
    <tbody>
    <tr>
        <th width="8%"><strong>字符</strong></th>
        <td width="17%"><strong>电码符号</strong></td>
        <th width="8%"><strong>字符</strong></th>
        <td width="17%"><strong>电码符号</strong></td>
        <th width="8%"><strong>字符</strong></th>
        <td width="17%"><strong>电码符号</strong></td>
    </tr>
    <tr>
        <th>0</th>
        <td>━ ━ ━ ━ ━</td>
        <th>1</th>
        <td>．━ ━ ━ ━</td>
        <th>2</th>
        <td>．．━ ━ ━</td>
    </tr>
    <tr>
        <th>3</th>
        <td>．．．━ ━</td>
        <th>4</th>
        <td>．．．．━</td>
        <th>5</th>
        <td>．．．．．</td>
    </tr>
    <tr>
        <th>6</th>
        <td>━ ．．．．</td>
        <th>7</th>
        <td>━ ━ ．．．</td>
        <th>8</th>
        <td>━ ━ ━ ．．</td>
    </tr>
    <tr>
        <th>9</th>
        <td>━ ━ ━ ━ ．</td>
        <th>　</th>
        <td>　</td>
        <th>　</th>
        <td>　</td>
    </tr>
    </tbody>
</table>
<h5>三、标点符号的莫尔斯电码加密</h5>
<table class="table table-striped table-bordered">
    <tr>
    <tr>
        <th width="8%"><strong>字符</strong></th>
        <td width="17%"><strong>电码符号</strong></td>
        <th width="8%"><strong>字符</strong></th>
        <td width="17%"><strong>电码符号</strong></td>
        <th width="8%"><strong>字符</strong></th>
        <td width="17%"><strong>电码符号</strong></td>
    </tr>
    <tr>
        <th title="句号">.</th>
        <td title="句号">．━ ．━ ．━</td>
        <th title="冒号">:</th>
        <td title="冒号">━ ━ ━ ．．．</td>
        <th title="逗号">,</th>
        <td title="逗号">━ ━ ．．━ ━</td>
    </tr>
    <tr>
        <th title="分号">;</th>
        <td title="分号">━ ．━ ．━ ．</td>
        <th title="问号">?</th>
        <td title="问号">．．━ ━ ．．</td>
        <th title="等号">=</th>
        <td title="等号">━ ．．．━</td>
    </tr>
    <tr>
        <th title="省略符">'</th>
        <td title="省略符">．━ ━ ━ ━ ．</td>
        <th title="斜线">/</th>
        <td title="斜线">━ ．．━ ．</td>
        <th title="叹号">!</th>
        <td title="叹号">━ ．━ ．━ ━</td>
        </tr>
    <tr>
        <th title="前括号">(</th>
        <td title="前括号">━ ．━ ━ ．</td>
        <th title="后括号">)</th>
        <td title="后括号">━ ．━ ━ ．━</td>
        <th title="美元">$</th>
        <td title="美元">．．．━ ．．━</td>

    </tr>
    <tr>
        <th title="">&amp;</th>
        <td title="">． ．．．</td>
        <th title="连字号">━ </th>
        <td title="连字号">━ ．．．．━</td>
        <th title="下划线">_</th>
        <td title="下划线">．．━ ━ ．━</td>

    </tr>
    </tr>
        <th title="双引号">"</th>
        <td title="双引号">．━ ．．━ ．</td>
        <th title="">@</th>
        <td title="">．━ ━ ．━ ．</td>
        <th>　</th>
        <td>　</td>
    </tr>
    </tbody>
</table>